/* Teaglass
 *
 * A* pathfinding visualized in an OpenGL 3d environment.
 *
 * By: M. Etheredge
 *     S. Brattinga
 */

#include "renderer.h"

#include <time.h>

int main( int argc, char **argv )
{
    int goalX, goalY, grid;
    char render;

    puts( "Teaglass version 0.1\nBy M.E. Etheredge & S. Brattinga\n\nRecommended grid size between 50 and 100,\nthe renderer is currently not optimized and will become very slow above 200,\n(this will only be a problem with rendering, when not rendering use any grid size)" );

    printf( "Please specify the grid size: " ); std::cin >> grid;
    printf( "Please specify the goal x between 0 and 1 minus horizontal grid size: ");  std::cin >> goalX;
    printf( "Please specify the goal y between 0 and 1 minus vertical grid size: ");  std::cin >> goalY;

    if( goalX > grid - 1 )
    {
        goalX = grid - 1;
    }
    if( goalY > grid - 1 )
    {
        goalY = grid - 1;
    }

    printf( "Nodes in grid: %i\n", grid * grid );

    if( grid > 100 )
    {
    	puts( "Going to build a gigantic list, expect slow rendering!" );

    	Renderer::g_LargeGrid = true;
    }

    clock_t start = clock();

	Grid *g = new Grid( grid, grid );
	g->BuildList();
	g->SetGoal( 0, 0 );
	g->SetEnd( goalX, goalY );
	g->BuildPath();
	Renderer::g_Grid = g;

	float d = ((double)clock() - start) / CLOCKS_PER_SEC;
	if( d == 0.0f )
	{
		puts( "Time to calculate path: instant" );
	}
	else
	{
		printf( "Time to calculate path: %f seconds\n", d );
	}

	printf( "Do you want to render? (y/n) ");  std::cin >> render;

	if( render != 'n' )
	{
		puts( "Stepping into rendering." );

		Renderer::Run( argc, argv );
	}

	Renderer::Cleanup();

    return 1;
}

